package com.example.yuejian.yuejian.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.adapter.MyOrderAdapter;
import com.example.yuejian.yuejian.base.BaseActivity;
import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.bean.Order;
import com.example.yuejian.yuejian.model.UserModel;

import java.util.List;

public class MyOrderActivity extends BaseActivity {

 private  RecyclerView recyclerView;
    private ImageView btn_back;
    List<Order> list;
    private ModleListListener<Order> modleListListener=new ModleListListener<Order>() {
        @Override
        public void onResponse(List<Order> l) {
            list=l;
            recyclerView.setAdapter(new MyOrderAdapter(getApplication(),list));

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplication(),"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order);
        initViews();
        getData();
        back();
    }
    private void initViews()
    { recyclerView=(RecyclerView)findViewById(R.id.my_order_recycleview);
        // GridLayoutManager gm = new GridLayoutManager(this.getActivity(),2);
        // 网格是的list布局   2列
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        //recyclerView.setLayoutManager(gm);


    }
    private  void getData()
    {
        UserModel userModel=new UserModel();
       userModel.myOrderList(getUser_id(),modleListListener);

    }
    private void back()
    {
        btn_back=(ImageView)findViewById(R.id.imgBtn_myorder_back);
        btn_back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });

    }
}
